package com.coach.util;

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.google.common.collect.Lists;

public class ResponseDataHelper{
	
	
	
	 // 提供一个公共的，用于对一般性List<T> 类型的json 生成方法
    public static <T> String getJsonResult(boolean isSuccess, int errorCode, 
            String errorMessage, List<T> list){


        BaseResponse<T> response = new BaseResponse<T>();

        response.setSuccess(isSuccess);
        response.setErrorCode(errorCode);
        response.setErrorMessage(errorMessage);

        if(list == null || list.isEmpty()){
            list = Lists.newArrayList();
        }

        response.setData(list);

        // 设置json 全局时间转换格式
        JSON.DEFFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
    
        SerializerFeature[] sf = { SerializerFeature.WriteNullNumberAsZero,
                SerializerFeature.WriteNullStringAsEmpty,
                SerializerFeature.WriteMapNullValue,
                SerializerFeature.DisableCircularReferenceDetect,
                SerializerFeature.WriteDateUseDateFormat };
    
        return JSON.toJSONString(response, sf);
    }

	
	
}